package com.hk.app.utils;

import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * Created by Antinomy on 17/9/26.
 */
public class TimeService {

    public static final String DATE_FORMAT = "yyyy-MM-dd";

    // Date format yyyy-MM-dd
    public static Boolean isBetweenDate(String checkDate , String beginDate, String endDate){

        LocalDate begin = LocalDate.parse(beginDate, DateTimeFormatter.ofPattern(DATE_FORMAT));
        LocalDate end = LocalDate.parse(endDate, DateTimeFormatter.ofPattern(DATE_FORMAT));
        LocalDate check = LocalDate.parse(checkDate, DateTimeFormatter.ofPattern(DATE_FORMAT));

        boolean isEqualOrAfterBegin = check.isEqual(begin) || check.isAfter(begin);
        boolean isEqualOrBeforeEnd = check.isEqual(end) || check.isBefore(end);

        if(isEqualOrAfterBegin && isEqualOrBeforeEnd) {
            return true;
        }

        return false;
    }

    public static String today() {
        return  today(null);
    }
    public static String today(String format) {

        if(StringUtils.isBlank(format)){
            format =  DATE_FORMAT;
        }

        DateTimeFormatter formatPattern=DateTimeFormatter.ofPattern(format);
        return  LocalDate.now().format(formatPattern);
    }
}
